<?php
$pagina = isset ( $_GET ['p'] ) ? $_GET ['p'] : 0;
$limit = 3;
$offset = $pagina == 0 ? 0 : ($pagina * $limit);
$qtd_sql = $conn->query ( "select count(codigo) from postagem where estado = 'C'" );
$qtd = $qtd_sql->fetch ( PDO::FETCH_NUM );
if ($qtd [0] > 0) {
	if ($qtd [0] != $limit) {
		$n_pag = ceil ( $qtd [0] / $limit );
	} else {
		$n_pag = 1;
	}
	$sql_post = $conn->query ( "select * from postagem where estado = 'C' order by data desc , hora desc limit $limit offset $offset" );
	while ( $post = $sql_post->fetch ( PDO::FETCH_ASSOC ) ) {
		?>
<h3 class="page-header">
	<a href="index.php?pag=post&cod=<?php echo $post['codigo']?>"><img src="images/iconphp.png" width="32" height="32"/><b><?php echo $post['titulo']?></b><br/> <small>by <?php echo $post['usuario'] .' em '.dataBancoByPt($post['data'])?></small></a>
</h3>
<p><?php echo $post['resumo']?></p>
<p class="text-right"><a class="btn btn-primary" href="index.php?pag=post&cod=<?php echo $post['codigo']?>">ler mais</a></p>
<?php }?>
<div class="row">
	<div class="col-lg-12">
		<ul class="pager" style="cursor: pointer">
		<?php
			echo $pagina == 0 ? '<li class="previous disabled"><span>Postagem Atual</span></li>' : '<li class="previous"><a href="index.php?p=' . ($pagina - 1) . '"><span>Postagem Atual</span></a></li>';
			echo $pagina == ($n_pag - 1) ? '<li class="next disabled"><span>Pastagem Antiga</span></li>' : '<li class="next"><a href="index.php?p=' . ($pagina + 1) . '"><span>Pastagem Antiga</span></a></li>';
		?>
		</ul>
	</div>
</div>
<?php
}
?>